Skip to content

net: support sync connect for BoundSocket#64375

Open
guybedford wants to merge 1 commit into
nodejs:mainfrom
guybedford:bound-socket-sync-connect
Open

net: support sync connect for BoundSocket#64375
guybedford wants to merge 1 commit into
nodejs:mainfrom
guybedford:bound-socket-sync-connect

Conversation

@guybedford

Copy link
Copy Markdown
Contributor

This allows obtaining socket.localAddress / socket.localPort synchronously, immediately after socket.connect(), when the socket is constructed from a net.BoundSocket.

#63951 added bind2()-style early binding for net.Socket, enabling synchronous local port reservation. This extends the same idea to connect(): the kernel resolves the concrete source address (autobind + source selection) inside the connect(2) syscall itself (without blocking), so a bound socket connecting to an IP literal can provide that address immediately matching POSIX/libuv semantics.

net.Socket.connect() normally defers connect(2) to a later tick due to the DNS lookup step, which doesn't exist for a net.BoundSocket, so connect(2) can be issued synchronously.

Tests are included for a concrete source resolved via localAddress/localPort synchronously after connect(), as well as a synchronous throw.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem. labels Jul 8, 2026
When a net.Socket is constructed from a net.BoundSocket, support
synchronous connect().

Signed-off-by: Guy Bedford <guybedford@gmail.com>
@guybedford guybedford force-pushed the bound-socket-sync-connect branch from f731ea6 to a607d87 Compare July 8, 2026 23:51
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.24%. Comparing base (0032189) to head (a607d87).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64375      +/-   ##
==========================================
+ Coverage   90.23%   90.24%   +0.01%     
==========================================
  Files         741      741              
  Lines      241194   241210      +16     
  Branches    45432    45434       +2     
==========================================
+ Hits       217640   217692      +52     
+ Misses      15129    15085      -44     
- Partials     8425     8433       +8     
Files with missing lines Coverage Δ
lib/net.js 94.63% <100.00%> (+0.03%) ⬆️

... and 29 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants